﻿/**************************************************************
*作者：Leon
*创建时间：2022/4/5 16:31:25
**************************************************************/
using System.Windows;
using System.Windows.Controls;

namespace Lad.DrawProject.Controls;

public class DesignerItemsControlItemStyleSelector : StyleSelector
{
    static DesignerItemsControlItemStyleSelector()
    {
        Instance = new DesignerItemsControlItemStyleSelector();
    }

    public static DesignerItemsControlItemStyleSelector Instance
    {
        get;
        private set;
    }


    public override Style? SelectStyle(object item, DependencyObject container)
    {
        ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(container);
        if (itemsControl == null)
            throw new InvalidOperationException("DesignerItemsControlItemStyleSelector : Could not find ItemsControl");


        if(item is DataControlViewModel)
            return (Style)itemsControl.FindResource("dataControlItemStyle");
        else if (item is DesignerItemViewModelBase)
            return (Style)itemsControl.FindResource("designerItemStyle");

        return null;
    }
}
